using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel.Design.Serialization;
using System.CodeDom;
using System.ComponentModel;

namespace XnaDesignerGenerator
{
    public class XnaGameGenerator : CodeDomSerializer
    {
        public override object Serialize(IDesignerSerializationManager manager, object value)
        {
            XnaGame component = (XnaGame)value;
            CodeStatementCollection statements = new CodeStatementCollection();
            if (component != null)
            {
                /*statements.Add(new CodeCommentStatement(" "));
                statements.Add(new CodeCommentStatement(" " + component.Site.Name));
                statements.Add(new CodeCommentStatement(" "));*/
                //Initialisation de la variable component1
                statements.Add(new CodeVariableDeclarationStatement(
                    component.GetType(),
                    component.Site.Name,
                    new CodeObjectCreateExpression(component.GetType(), new CodeExpression[] { })));

                //CodeStatementCollection statements= base.Serialize(manager, value) as CodeStatementCollection;
                if (component.GameType != null)
                {
                    statements.Add(new CodeAssignStatement(
                        new CodePropertyReferenceExpression(new CodeVariableReferenceExpression(component.Site.Name), "Game"),
                        new CodeObjectCreateExpression(component.GameType, new CodeExpression[] { })));
                    statements.Add(new CodeAssignStatement(
                        new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Game"),
                        new CodePropertyReferenceExpression(new CodeVariableReferenceExpression(component.Site.Name), "Game")));
                }
            }
            return statements;
        }
    }
}
